package A1动态规划;

public class LC_392判断子序列 {
    public boolean isSubsequence(String s, String t) {
        if(s==null && t==null || s.length()==0 && t.length()==0)
            return true;
        if(t==null||t.length()==0)
            return false;
        int[][] dp=new int[s.length()+1][t.length()+1];
        for(int i=0;i<s.length();i++)
            dp[i][0]=0;
        for(int j=0;j<t.length();j++)
            dp[0][j]=0;
        char[] c1=s.toCharArray();
        char[] c2=t.toCharArray();
        for(int i=1;i<=c1.length;i++)
            for(int j=1;j<=c2.length;j++){
                if(c1[i-1]==c2[j-1])
                    dp[i][j]=dp[i-1][j-1]+1;
                else
                    dp[i][j]=Math.max(dp[i][j-1],dp[i-1][j]);
            }
        if(dp[s.length()][t.length()]==s.length())
            return true;
        else
            return false;
    }
}
